<template>
  <div class="weui-cell">
    <div class="weui-cell__bd">{{device.lable}}</div>
    <div class="lable">{{lable[device.value]}}</div>
    <picker @change="action" :value="device.value" :range="lable">
      <button class="weui-btn mini-btn" type="primary" size="mini" >{{device.lable}}</button>
    </picker>
  </div>
</template>

<script>
import { publishMessage } from "@/utils";
export default {
  name: "mpvue-button",
  data() {
    return {
      lable: [],
      value: []
    };
  },
  props: {
    device: Object
    // {
    //   type: "picker",
    //   lable: "选择",
    //   key:'select',
    //   value: 1,
    //   options: [
    //     {
    //       lable: "lable1",
    //       value: "0"
    //     },
    //     {
    //       lable: "lable2",
    //       value: "1"
    //     },
    //     {
    //       lable: "lable3",
    //       value: "2"
    //     }
    //   ]
    // }
  },
  mounted() {
    var val = this.device.options;
    for (let index in val) {
      this.lable.push(val[index].lable);
      this.value.push(val[index].value);
    }
  },
  methods: {
    action(e) {
      this.device.value = e.mp.detail.value
      publishMessage(`{"${this.device.key}":${e.mp.detail.value}}`);
    }
  }
};
</script>

<style>
.lable{
  width: 60%;
  text-align: center;
  color: #e5e5e5;
}
</style>
